// Copyright (c) 2009 Mike Haight, Andy Kipp
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.

#include "Actor.h"

using namespace HandBanana::Game;
using namespace HandBanana::Core;

Actor::Actor(void) : mLocation(0.0f, 0.0f), mSize(0.0f, 0.0f)
{
}


Actor::~Actor(void)
{
}


HandBanana::Core::Location Actor::Location(void) const
{
    return mLocation;
}


void Actor::Location(const HandBanana::Core::Location& value)
{
    mLocation = value;
}


HandBanana::Core::Size Actor::Size(void) const
{
    return mSize;
}


void Actor::Size(const HandBanana::Core::Size& value)
{
    mSize = value;
}


HandBanana::Core::Rectangle Actor::CollisionOffset(void) const
{
    return mOffset;
}


void Actor::CollisionOffset(const HandBanana::Core::Rectangle& value)
{
    mOffset = value;
}


HandBanana::Core::Rectangle Actor::CalculateCollisionRectangle(void) const
{
    HandBanana::Core::Rectangle rect = HandBanana::Core::Rectangle(
                                                            Location().X + CollisionOffset().X(),
                                                            Location().Y + CollisionOffset().Y(),
                                                            CollisionOffset().Width(),
                                                            CollisionOffset().Height());
    return rect;
}

bool Actor::Move(const HandBanana::Core::Location& argVelocity)
{
    //if (argVelocity.X == 0 && argVelocity.Y == 0)
    //    return true;

    //// Calculate new Location
    //Coordinates::Location newLocation = Coordinates::Location(Location.X + argVelocity.X, Location.Y + argVelocity.Y);

    //// Get World
    //World^ world = Core::Engine::GetWorld();

    //if (newLocation.X < 0)
    //{
    //    newLocation.X = 0;
    //} 
    //else if (newLocation.X + Size.Width > world->Size.Width)
    //{
    //    newLocation.X = world->Size.Width - Size.Width;
    //}

    //if (newLocation.Y < 0)
    //{
    //    newLocation.Y = 0;
    //} 
    //else if (newLocation.Y + Size.Height > world->Size.Height)
    //{
    //    newLocation.Y = world->Size.Height - Size.Height;
    //}

    //// Calculate collision Rectangle of new Location
    //Coordinates::Rectangle newCollisionRectangle = Coordinates::Rectangle(newLocation.X + CollisionOffset.X, newLocation.Y + CollisionOffset.Y, CollisionOffset.Width, CollisionOffset.Height); 

    //// Get WorldObjects from Background Layer at new collision rectangle
    //List<WorldObject^> objects = world->Layers["Background"]->GetObjects(newCollisionRectangle);

    //bool canMove = true;
    //for each (WorldObject^ object in objects)
    //{
    //    if ( (object->CollisionRectangle.IsEmpty() == false) && (newCollisionRectangle.Intersects(object->CollisionRectangle) == true) )
    //    {
    //        canMove = false;
    //        break;
    //    }
    //}

    //if (canMove)
    //{
    //    // Update Location
    //    Location = newLocaion;
    //}

    //return canMove;
    return false;
}